<?php
/*
Gets the html table to manage items.
*/
function get_ssf_manage_table($items,$controller)
{
	$CI =& get_instance();
	$table='<table class="tablesorter" id="sortable_table">';
	
	$headers = array('<input type="checkbox" id="select_all" />', 
	$CI->lang->line('ssf_name'),
	$CI->lang->line('ssf_computation'),
	$CI->lang->line('ssf_presentation'),
	$CI->lang->line('common_modify'));
	
	$table.='<thead><tr>';
	foreach($headers as $header)
	{
		$table.="<th>$header</th>";
	}
	$table.='</tr></thead><tbody>';
	$table.=get_ssf_manage_table_data_rows($items,$controller);
	$table.='</tbody></table>';
	return $table;
}

/*
Gets the html data rows for the items.
*/
function get_ssf_manage_table_data_rows($items,$controller)
{
	$CI =& get_instance();
	$table_data_rows='';
	
	foreach($items as $item)
	{
		$table_data_rows.=get_ssf_data_row($item,$controller);
	}
	
	if(empty($items))
	{
		$table_data_rows.="<tr><td colspan='8'><div class='warning_message' style='padding:7px;'>".$CI->lang->line('common_empty')."</div></tr></tr>";
	}
	return $table_data_rows;
}

function get_ssf_data_row($item,$controller)
{
	$CI =& get_instance();
	$controller_name=$CI->uri->segment(1);
	$width = $controller->get_form_width()+300;
	
	$table_data_row='<tr>';
	$table_data_row.="<td width='3%'><input type='checkbox' id='item_$item[0]' value='".$item[0]."'/></td>";
	$table_data_row.='<td >'.$item[1].'</td>';
	$table_data_row.='<td >'.$item[2].'</td>';
	$table_data_row.='<td >'.$item[3].'</td>';
	$table_data_row.='<td >'.anchor($controller_name."/edit_ssf/$item[0]/width:$width", $CI->lang->line('ssf_edit_computation'),array('class'=>'thickbox','title'=>$CI->lang->line('ssf_computation'))).'&nbsp;&nbsp;'.anchor($controller_name."/edit_ssf_present/$item[0]/width:$width", $CI->lang->line('ssf_edit_presentation'),array('class'=>'thickbox','title'=>$CI->lang->line('ssf_presentation'))).'</td>';		
	$table_data_row.='</tr>';
	
	return $table_data_row;
}


///////////////// Editing of ssf Components //////////////////////////
/*
Gets the html table to manage items.
*/
function edit_ssf_items_manage_table($items,$controller,$start_ssf)
{
	$CI =& get_instance();
	$table='<table class="tablesorter" id="sortable_table">';
	
	$headers = array(
	$CI->lang->line('common_tier'),
	$CI->lang->line('staffs_default_netwage'),
	$CI->lang->line('common_perc_value'),
	$CI->lang->line('common_modify')
	);
	
	$table.='<thead><tr>';
	foreach($headers as $header)
	{
		$table.="<th>$header</th>";
	}
	$table.='</tr></thead><tbody>';
	$table.=edit_ssf_items_manage_table_data_rows($items,$controller,$start_ssf);
	$table.='</tbody></table>';
	return $table;
}

/*
Gets the html data rows for the items.
*/
function edit_ssf_items_manage_table_data_rows($items,$controller,$start_ssf)
{
	$CI =& get_instance();
	$table_data_rows='';
	
	foreach($items->result() as $item)
	{
		$table_data_rows.=edit_ssf_item_data_row($item,$controller,$start_ssf);
	}
	
	if($items->num_rows()==0)
	{
		$table_data_rows.="<tr><td colspan='8'><div class='warning_message' style='padding:7px;'>".$CI->lang->line('common_empty')."</div><input type='hidden' name='hidden_empty' id='hidden_empty' value='0'/></tr></tr>";
	}
	else
	{
		$table_data_rows.="<tr><td colspan='8'><input type='hidden' name='hidden_empty' id='hidden_empty' value='1'/></td></tr>";
	}
	return $table_data_rows;
}

function edit_ssf_item_data_row($item,$controller,$start_ssf)
{
	$CI =& get_instance();
	$controller_name=$CI->uri->segment(1);
	
	$checked_str = '';
	
	if($item->order == $start_ssf)
	{
		$checked_str = "checked=checked";
	}
	
	$tier = "Tier ".$item->order." <input type='hidden' name='order[]' id='order[]' value='".$item->order."'/>"; 
	$default = "<input type='radio' name='order_radio' id='order".$item->order."' value='".$item->order."' $checked_str/>"; 
	$perc_value = "<input type='text' name='percent_value[]' id='percent_value[]' value='".$item->percent_value."'/>%<input type='hidden' name='item_update_id[]' id='item_update_id[]' value='".$item->ssf_item_id."'/>";
	$delete = "<span style='cursor:pointer;' onclick='delete_ssf_items(".$item->ssf_item_id.",".$item->ssf_id.");'>Delete</span>";
	
	//$delete = "<a href='#' id='delete' onclick='delete_ssf_item(".$item->ssf_item_id.",".$item->ssf_id.");' >Delete</a>";
	//$delete = anchor($controller_name."/edit_ssf/$item[0]/width:$width", $CI->lang->line('common_edit'),array('class'=>'thickbox','title'=>$CI->lang->line($controller_name.'_update'),'onclick'=>'delete_ssf_item('.$item->ssf_item_id.','.$item->ssf_id.');'));
	//$delete = form_button(array('name'=>'delete','id'=>'delete','onclick'=>'delete_ssf_item('.$item->ssf_item_id.','.$item->ssf_id.');','class'=>'submit_button'),'Delete');
	
	$table_data_row='<tr>';
	$table_data_row.='<td >'.$tier.'</td>';
	$table_data_row.='<td >'.$default.'</td>';
	$table_data_row.='<td >'.$perc_value.'</td>';
	$table_data_row.='<td >'.$delete.'</td>';
	$table_data_row.='</tr>';
	
	return $table_data_row;
}
?>